/**
  ******************************************************************************
  * @file    lwrb_demo.c
  * @brief   This file provides code for the configuration
  *          of the IIC instances.
  ******************************************************************************
  * @attention
  *
  * @Author: 中国赛宝 CEPREI
  * @Date: 2023/11/06 22:11:36
  * All rights reserved.
  *
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "lwrb.h"

/* Defines -------------------------------------------------------------------*/

/* Variables -----------------------------------------------------------------*/
//环形队列
lwrb_t lwrb = {0};
//队列缓存区
uint8_t lwrb_buff[1024 * 10] = {0};
//输入输出数据
uint8_t lwrb_input[8] = {1,2,3,4,5,6,7,8};
uint8_t lwrb_output[16] = {0};
//队列剩余字节数
uint32_t lwrb_num;

/* Prototypes ----------------------------------------------------------------*/
/*
*********************************************************************************************************
*	函 数 名: DemoLWRBInit
*	功能说明: 初始化环形队列例程
*	形    参: 无
*	返 回 值: 无
*********************************************************************************************************
*/
void DemoLWRBInit(void)
{
    uint8_t state = 0;
    //初始化环形队列句柄
    lwrb_init(&lwrb, lwrb_buff, sizeof(lwrb_buff));
    //检查是否初始化成功
    state = lwrb_is_ready(&lwrb);
}

void DemoLWRB(void)
{
    //环形队列写
    lwrb_write(&lwrb,lwrb_input,sizeof(lwrb_input));
    lwrb_write(&lwrb,lwrb_input,sizeof(lwrb_input));
    lwrb_write(&lwrb,lwrb_input,sizeof(lwrb_input));
    //环形队列读
    lwrb_read(&lwrb,lwrb_output,sizeof(lwrb_output));
    lwrb_num = lwrb_get_free(&lwrb);
    HAL_Delay(1000);
    //释放缓冲内存
//    lwrb_free(&lwrb);
}
